import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class;

/**
 * FieldPermission - 安全组字段权限tab
 * @date: 2019-11-27

 */
import React, { Component } from 'react';
import { Table } from 'antd';
import { Bind } from 'lodash-decorators';
import { tableScrollWidth } from 'utils/utils';
import intl from 'utils/intl';
import FieldConfigDrawer from "./Drawer";
var FieldPermissionTab = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_Component) {
  _inherits(FieldPermissionTab, _Component);

  var _super = _createSuper(FieldPermissionTab);

  function FieldPermissionTab(props) {
    var _this;

    _classCallCheck(this, FieldPermissionTab);

    _this = _super.call(this, props);
    _this.state = {
      visible: false,
      currentInterface: {}
    };
    return _this;
  }

  _createClass(FieldPermissionTab, [{
    key: "handleOpenDrawer",
    value: function handleOpenDrawer(record) {
      this.setState({
        currentInterface: record,
        visible: true
      });
    }
  }, {
    key: "handleCloseDrawer",
    value: function handleCloseDrawer() {
      this.setState({
        visible: false,
        currentInterface: {}
      });
    }
  }, {
    key: "columns",
    get: function get() {
      var _this2 = this;

      return [{
        title: intl.get('ciam.roleManagement.model.api.serviceName').d('服务名'),
        dataIndex: 'serviceName'
      }, {
        title: intl.get('ciam.roleManagement.model.api.method').d('请求方式'),
        dataIndex: 'method'
      }, {
        title: intl.get('ciam.roleManagement.model.api.path').d('请求路径'),
        dataIndex: 'path'
      }, {
        title: intl.get('ciam.roleManagement.model.api.description').d('请求描述'),
        dataIndex: 'description',
        width: 300
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 120,
        fixed: 'right',
        render: function render(_, record) {
          return /*#__PURE__*/React.createElement("span", {
            className: "action-link"
          }, /*#__PURE__*/React.createElement("a", {
            onClick: function onClick() {
              return _this2.handleOpenDrawer(record);
            }
          }, intl.get('ciam.roleManagement.model.api.fdPermissionMaintenance').d('字段权限维护')));
        }
      }];
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          dataSource = _this$props.dataSource,
          loading = _this$props.loading,
          pagination = _this$props.pagination,
          _this$props$onFetchFi = _this$props.onFetchFieldConfigList,
          onFetchFieldConfigList = _this$props$onFetchFi === void 0 ? function () {} : _this$props$onFetchFi,
          queryFieldConfigLoading = _this$props.queryFieldConfigLoading;
      var _this$state = this.state,
          visible = _this$state.visible,
          currentInterface = _this$state.currentInterface;
      var tableProps = {
        rowKey: 'id',
        columns: this.columns,
        bordered: true,
        dataSource: dataSource,
        loading: loading,
        pagination: pagination,
        scroll: {
          x: tableScrollWidth(this.columns)
        }
      };
      var drawerProps = {
        visible: visible,
        loading: queryFieldConfigLoading,
        currentInterface: currentInterface,
        onFetchDetail: onFetchFieldConfigList,
        onCancel: this.handleCloseDrawer
      };
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Table, tableProps), /*#__PURE__*/React.createElement(FieldConfigDrawer, drawerProps));
    }
  }]);

  return FieldPermissionTab;
}(Component), (_applyDecoratedDescriptor(_class.prototype, "handleOpenDrawer", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleOpenDrawer"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleCloseDrawer", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleCloseDrawer"), _class.prototype)), _class));
export { FieldPermissionTab as default };